package com.sikaryofficial.backend.controller.information;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.annotation.Repeat;
import com.sikaryofficial.backend.domain.dto.req.information.FollowFansListReq;
import com.sikaryofficial.backend.domain.dto.req.information.FollowFriendListReq;
import com.sikaryofficial.backend.domain.dto.req.information.FollowSaveReq;
import com.sikaryofficial.backend.domain.dto.resp.information.FollowDTO;
import com.sikaryofficial.backend.manager.information.FollowManager;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 关注Controller
 *
 * @author qinjinyuan
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/article/follow")
@Api(tags = "资讯-关注服务")
@SuppressWarnings(value = "unchecked")
public class FollowController extends BaseController {
    @Autowired
    private FollowManager followManager;

    /**
     * 查询关注列表
     */
    @ApiOperation("好友分页列表")
    @PostMapping("/friend/listPage")
    @Repeat
    public PageResult<FollowDTO> friendListPage(@Validated @RequestBody FollowFriendListReq req) {
        IPage<FollowDTO> page = followManager.friendListPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    @ApiOperation("粉丝分页列表")
    @PostMapping("/fans/listPage")
    @Repeat
    public PageResult<FollowDTO> fansListPage(@Validated @RequestBody FollowFansListReq req) {
        IPage<FollowDTO> page = followManager.fansListPage(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }

    /**
     * 新增关注
     */
    @ApiOperation("保存关注")
    @PostMapping("/save")
    @Repeat
    public R<Boolean> add(@Validated @RequestBody FollowSaveReq req) {
        return R.ok(followManager.saveOrUpdate(req));
    }
}
